package operation;

import book.Book;
import book.Booklist;

import java.util.Scanner;

public class Add implements Canoperation {
    public void work(Booklist booklist){
        Scanner sc = new Scanner(System.in);
        System.out.print("书名：");
        String name = sc.nextLine();
        System.out.print("作者：");
        String author = sc.nextLine();
        System.out.print("类型：");
        String type = sc.nextLine();
        System.out.print("价格：");
        double price = sc.nextDouble();
        Book book = new Book(name,author,type,price,false);
        int sum = booklist.getBooksum();
        for(int i = 0; i < sum; i++){
            Book book1 = booklist.getbook(i);
            if(book.getName().equals(book1.getName())) {
                System.out.println("这本书已经存在");
                return;
            }
        }

        booklist.setbook(sum,book);
        System.out.println("添加成功");
        booklist.setBooksum(sum+1);
    }
}
